package net.uhuijia.user.usermall.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import net.uhuijia.appbase.controller.BaseController;
import net.uhuijia.user.usermall.persistence.model.UserMall;
import net.uhuijia.user.usermall.persistence.model.UserMallExample;
import net.uhuijia.user.usermall.service.UserMallService;
import net.uhuijia.user.usertoken.service.UserTokenService;
import net.uhuijia.utils.StringHelper;

/**
 * 对其它模块提供
 * @author  许小宝
 */
@RestController
@RequestMapping(value="/client/usermall")
public class UserMallClientController
     extends BaseController<UserMallService, UserMall, UserMallExample> {
	/**
	 * 用户令牌服务
	 */
	private UserTokenService userTokenService;
	@Autowired
	public void setUserTokenService(UserTokenService userTokenService) {
		this.userTokenService = userTokenService;
	}

	/**
	 * 验证 token秘 device 如果成功则返回用户信息，如果失败返回空
	 * @param device 登入设备（pc\xcx\app\gzh）
	 * @param token 用户令牌
	 * @return UserMall
	 */
	@RequestMapping(value = "/auth/{device}/{token}")
    @ResponseBody
	public UserMall auth(@PathVariable("device")String device,  @PathVariable("token")String token ) {
		UserMall user = null;
		if( StringHelper.isNotBlanks(device,token) ){
			user = userTokenService.auth(device,token);
		}
		return user;
	}
}